import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    ToastAndroid,
    Platform,
    BackHandler,
} from 'react-native';
/**
 * 由 WangYu 创建
 * 日期 2017/9/5
 */
import {Tabs} from "./Tabs";
import { addNavigationHelpers } from 'react-navigation';

export default class MainPage extends Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        if (Platform.OS === 'android') {
            BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    componentWillUnmount() {
        if (Platform.OS === 'android') {
            BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    onBackAndroid = () => {
        //到了主页了
        if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
            //最近2秒内按过back键，可以退出应用。
            return false;
        }
        this.lastBackPressed = Date.now();
        ToastAndroid.show('再按一次退出应用', ToastAndroid.SHORT);
        return true;
    };

    render() {
        const { dispatch, navigation } = this.props;
        return (
            <Tabs navigation={addNavigationHelpers({
                dispatch: dispatch,
                state: navigation,
            })}
            />
        );
    }

}

const styles = StyleSheet.create({
    iconStyle: {
        width: 25,
        height: 25,
    },
    titleStyle: {
        color: '#333333',
        fontSize: 12,
    },
    titleSelectStyle: {
        color: '#13227a',
        fontSize: 12,
    }

});
